package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("二狗");
        list.add("日穿钢板");
        list.add("王石头");
        System.out.println(list);
//        Comparator<String> c = new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                int olen1 = o1.length();
//                int olen2 = o2.length();
//                //return olen1-olen2;//升序
//                return olen2-olen1;//反过来减就是降序(从大到小)
//            }
//        };

//        Collections.sort(list,(o1,o2) -> o1.length()-o2.length());

//        Collections.sort(list,Comparator.comparingInt(String::length));


        list.sort((o1,o2) -> o1.length()-o2.length());

        System.out.println(list);
    }
}
